/**
 * @(#)basicView.js 0.3.0 2018-01-17
 * Copyright (c) 2017, YUNXI. All rights reserved.
 * YUNXI PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
import React, { Component } from 'react'
import { connect } from 'dva'
import cx from 'classnames'
import styles from './couponSettingStyle.less'
import { message, Row, Col, Select, Input, Form, Radio, Checkbox, Button, Table, Icon, DatePicker, InputNumber, Popconfirm, Modal } from 'antd'
import { get, cloneDeep } from "lodash";
import { request } from "config/request";
import config from "config/config";
import { Link, hashHistory } from 'dva/router';
import $ from 'jquery';
import moment from 'moment';
import { CollapsiblePanels } from 'widget/CollapsiblePanels/index'
const FormItem = Form.Item
const { Option } = Select
const RadioGroup = Radio.Group
const { TextArea } = Input
const CheckboxGroup = Checkbox.Group;
const { RangePicker } = DatePicker;
const formItemLayout = {
	labelCol: { span: 5 },
	wrapperCol: { span: 19 },
}

const ColLayout = {
	md: { span: 20 },
}

const options = [
	{ label: '君兰江山', value: '君兰江山' },
	{ label: '一号公馆', value: '一号公馆' },
	{ label: '美的君兰', value: '美的君兰' },
	{ label: '美的花湾城', value: '美的花湾城' },
	{ label: '江山美人', value: '江山美人' },
];
const CouponBasicView = function ({ dispatch, model, form }) {

	const { resetFields, getFieldDecorator, validateFields, setFieldsValue } = form

	const { namespace, modelObj } = model

	let { detail } = modelObj

	function inputChange(key, value) {
		resetFields();

		let resData = cloneDeep(detail);

		if (key === 'couponValidTime') {
			resData.startTime = value[0] ? value[0] : '';
			resData.expireDate = value[1] ? value[1] : '';
		} else {
			resData[key] = value;
		}

		dispatch({ type: `${namespace}/updateStore`, payload: { detail: resData } });
	}

	return (
		<div className="public_listMain">
			<CollapsiblePanels title="配置优惠券" hideUpDownBtn={true} className={styles.CouponBasic}>
				<Form>
					<Row>
						<Col {...ColLayout}>
							<FormItem {...formItemLayout} label="优惠券类型">
								{
									getFieldDecorator('type', {
										rules: [
											{ required: true, message: '请选择优惠券类型' },
										],
										initialValue: detail.type
									})
										(
										<Select
											placeholder='请选择优惠券类型'
											style={{ width: '300px' }}
											onChange={value => { inputChange('type', value) }}
										>
											<Option value="">请选择</Option>
											<Option value="1">代金券</Option>
											<Option value="2">折扣券</Option>
										</Select>
										)
								}
							</FormItem>
						</Col>
					</Row>
					<Row>
						<Col {...ColLayout}>
							<FormItem label={'优惠券名称'} {...formItemLayout}>
								{
									getFieldDecorator('name', {
										rules: [
											{ required: true, message: `优惠券名称不能为空` },
										],
										initialValue: detail.name
									})
										(<div>
											<Input
												style={{ width: '300px' }}
												placeholder={`请输入优惠券名称`}
												onChange={e => { inputChange('name', e.target.value) }}
											/>
										</div>)
								}
							</FormItem>
						</Col>
					</Row>
					<Row>
						<Col {...ColLayout}>
							<FormItem label={'发放总数'} {...formItemLayout}>
								{
									getFieldDecorator('circulation', {
										rules: [
											{ required: true, message: `发放总数不能为空` },
										],
										initialValue: detail.circulation
									})
										(<InputNumber
											max={99999999}
											min={1}
											precision={0}
											style={{ width: '100px' }}
											onChange={value => { inputChange('circulation', value) }}
										/>)
								}
							</FormItem>
						</Col>
					</Row>
					<div className={styles.btn}>
						<Button type="primary"  style={{ marginRight: '20px' }} onClick={() => { }}>保存</Button>
						<Button onClick={() => { hashHistory.push('/home/infoAdmin/couponList')}}>取消</Button>
					</div>
				</Form>
			</CollapsiblePanels>
		</div>
	)

}

export default Form.create()(CouponBasicView)
